//
//  ZHYNotificationManager.m
//  ZHYProject
//
//  Created by lc4y on 2017/12/21.
//  Copyright © 2017年 dtl. All rights reserved.
//

#import "ZHYNotificationManager.h"
#import <AudioToolbox/AudioToolbox.h>

#define ZHYIsRing @"ZHYIsRing"
#define ZHYIsShake @"ZHYIsShake"

@implementation ZHYNotificationManager

- (instancetype)init
{
    self = [super init];
    if (self) {
        _isRing = [ZHYFetch_Object(ZHYIsRing) boolValue];
        _isShake = [ZHYFetch_Object(ZHYIsShake) boolValue];
    }
    return self;
}

+ (ZHYNotificationManager *)notificationMananger {
    
    static ZHYNotificationManager *manager = nil;
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{
        manager = [[self alloc] init];
    });
    
    return manager;
}

- (void)setIsRing:(BOOL)isRing {
    _isRing = isRing;
    
    //缓存
    ZHYCache_Object(@(isRing), ZHYIsRing);
}

- (void)setIsShake:(BOOL)isShake {
    _isShake = isShake;
    //缓存
    ZHYCache_Object(@(isShake), ZHYIsShake);
}

- (void)notificationUserNewMessage {
    // 铃声+震动
    if( !self.isShake && !self.isRing ) {
        AudioServicesPlaySystemSound(kSystemSoundID_Vibrate); // 震动
        AudioServicesPlaySystemSound(1007);  // QQ新消息提示音
    } else if( !self.isShake ) {
        // 震动A
        AudioServicesPlaySystemSound(kSystemSoundID_Vibrate);
    } else if( !self.isRing ) {
        // 铃声
        AudioServicesPlaySystemSound(1007);
    }
}

@end
